package com.wn.ziroom.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wn.ziroom.entity.Room;
import com.wn.ziroom.entity.RoomImg;
import com.wn.ziroom.service.QuartersService;
import com.wn.ziroom.service.RoomImgService;
import com.wn.ziroom.service.RoomService;
import com.wn.ziroom.vo.Condition;
import com.wn.ziroom.vo.EsRoomVo;
import com.wn.ziroom.vo.RoomDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wangzhijia
 * @since 2023-02-23 02:27:54
 */
@Controller
@RequestMapping("/room")
public class RoomController {

    @Autowired
    private RoomService roomService;

    @Autowired
    private RoomImgService imgService;

    @Autowired
    private QuartersService quartersService;

    @ResponseBody
    @RequestMapping("/roomList")
    public Page<EsRoomVo> roomList(
            @RequestParam(defaultValue = "1") Integer num,
            @RequestParam(defaultValue = "9") Integer size,
            @RequestBody Condition condition
            ) {
//        Page<Room> roomList = roomService.getRoomList(num, size, condition);  基于动态sql实现
        Page<EsRoomVo> esRoomVoPage = roomService.getRoomListEs(num, size, condition);  //基于es实现
        return esRoomVoPage;
    }


    @RequestMapping("/toRoomDetail/{id}")
    public String toRoomDetail(@PathVariable Integer id, Map<String, Object> map) {
        RoomDetailVo roomDetail = roomService.getRoomDetail(id);
        List<RoomImg> roomImgs = imgService.getRoomImgs(id);

        map.put("imgs", roomImgs);
        map.put("roomInfo", roomDetail);
        return "/room/roomDetail";
    }
}

